import type { Router } from 'vue-router'
import { useTitle } from '@vueuse/core'
import { $t } from '@/locales'

// 改变网页标题
export function changeTitle(router: Router) {
  const titleRef = useTitle('common.home', {
    titleTemplate: (title) => {
      return `${$t(title)} - ${import.meta.env.VITE_GLOB_APP_TITLE}`
    },
  })
  router.beforeEach((to) => {
    const { title } = to.meta
    if (title) {
      titleRef.value = title
    }
  })
}
